﻿Imports System.Xml

Namespace HybrisItems.Model

    ''' <summary>
    ''' Configures the generated attribute at one relation end.
    ''' </summary>
    ''' <remarks></remarks>
    <Serializable()> _
    Public Class RelationElementModel

        Public Sub New()

        End Sub

        Public Sub New(Node As XmlNode)

            Fill(Node)

        End Sub

        ''' <summary>
        ''' Is this Model object correctly wired to its related Model objects
        ''' </summary>
        ''' <remarks></remarks>
        Public ReadOnly Property IsWired As Boolean
            Get
                Return ItemType IsNot Nothing
            End Get
        End Property
        Public Sub Fill(Node As XmlNode)

            'ToDo: Unset Config Properties
            ' Me.Description
            ' Me.Modifiers
            ' Me.Model
            ' Me.CustomProperties

            Me.Type = New CodeModel(Node, "type")

            'ToDo: Unset Config Properties
            ' Me.Qualifier
            ' Me.MetaType
            ' Me.Cardinality
            ' Me.Navigable
            ' Me.CollectionType

        End Sub

        Public Sub Wire(Model As EntireHybrisSystemModel)

            ItemType = Model.Types(Me.Type.Value)

        End Sub

        Public Property ItemType As ItemTypeModel

#Region "Config Properties"

        ''' <summary>
        ''' Documents this relation attribute. 
        ''' Will be cited at javadoc of generated getters/setters.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Description As String

        ''' <summary>
        ''' Defines properties for the attribute.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Modifiers As ModifiersModel

        ''' <summary>
        ''' Allows to configure model generation 
        ''' for this relation attribute used at servicelayer.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Model As AttributeModelModel

        ''' <summary>
        ''' Allows to configure custom properties for the relation attribute.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CustomProperties As CustomPropertiesModel

        ''' <summary>
        ''' Type of attribute which will be generated 
        ''' at type configured for opposite relation end.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Type As CodeModel

        ''' <summary>
        ''' Qualifier of attribute which will be generated 
        ''' at type configured for opposite relation end. If navigable is 
        ''' not set to false the qualifier is mandatory. Default is empty.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Qualifier As String

        ''' <summary>
        ''' The (meta)type which describes the attributes type. Must be type extending RelationDescriptor. 
        ''' Default is 'RelationDescriptor'.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property MetaType As String = "RelationDescriptor"

        ''' <summary>
        ''' The cardinality of this relation end. 
        ''' Choose 'one' for 'one' part of a 1:n relation 
        ''' or 'many' when part of a n:m relation. 
        ''' A 1:1 relation is not supported. Default is 'many'.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Cardinality

        Public Enum Cardinalities
            ''' <summary>
            ''' The element is the 'one' part of a 1:n relation
            ''' </summary>
            ''' <remarks></remarks>
            one
            ''' <summary>
            ''' The element is part of a n:m relation
            ''' </summary>
            ''' <remarks></remarks>
            many
        End Enum

        ''' <summary>
        ''' Is the relation navigable from this side. 
        ''' Can only be disabled for one side of many to many relation. 
        ''' If disabled, no qualifier as well as modifiers can be defined.
        '''  Default is 'true'.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Navigable As Boolean = True

        ''' <summary>
        ''' Configures the type of this collection if element has cardinality 'many'. 
        ''' Related attribute getter / setter will use corresponding java 
        ''' collection interfaces. Default is 'Collection'.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CollectionType As CollectionTypes = CollectionTypes.collection

        Public Enum CollectionTypes

            ''' <summary>
            ''' A collection that contains no duplicate elements.
            ''' </summary>
            ''' <remarks></remarks>
            [set]

            ''' <summary>
            ''' An ordered collection.
            ''' </summary>
            ''' <remarks></remarks>
            [list]

            ''' <summary>
            ''' A collection.
            ''' </summary>
            ''' <remarks></remarks>
            [collection]

        End Enum

#End Region

    End Class

End Namespace
